package com.fin.zw.intelligentbot.controller;


import com.fin.zw.intelligentbot.annotation.CurrentUser;
import com.fin.zw.intelligentbot.entity.SceneInfo;
import com.fin.zw.intelligentbot.model.request.SceneInfoRequest;
import com.fin.zw.intelligentbot.model.response.SceneInfoResponse;
import com.fin.zw.intelligentbot.model.session.SessionModel;
import com.fin.zw.intelligentbot.service.SceneInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/scene")
@Api(value = "场景管理",description = "场景管理")
public class SceneInfoController {

    @Autowired
    private SceneInfoService sceneInfoService;

    @GetMapping("/fetchPage")
    @ApiOperation(value = "查询所有的场景信息",notes = "查询所有的场景信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<SceneInfoResponse>> querySceneInfoAll(Pageable pageable,
                                                                  SceneInfoRequest request,
                                                                  @ApiIgnore @CurrentUser SessionModel sessionModel){
        Page<SceneInfoResponse> page = sceneInfoService.querySceneInfoAll(pageable,request,sessionModel);
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("/fetch")
    @ApiOperation(value = "查询所有的场景信息",notes = "查询所有的场景信息")
    public ResponseEntity<List<SceneInfo>> getSceneInfoList(@ApiIgnore @CurrentUser SessionModel sessionModel){
        List<SceneInfo> list = sceneInfoService.getSceneInfoList(sessionModel);
        return ResponseEntity.ok().body(list);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加场景信息",notes = "添加场景信息")
    public ResponseEntity<String> createSceneInfo(@RequestBody SceneInfoRequest request,
                                                @ApiIgnore @CurrentUser SessionModel sessionModel){
        sceneInfoService.createSceneInfo(request,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }

    @RequestMapping(value = "/update",method = {RequestMethod.PUT,RequestMethod.PATCH})
    @ApiOperation(value = "更新场景信息",notes = "更新场景信息")
    public ResponseEntity<String> updateSceneInfo(@RequestBody SceneInfoRequest request,
                                                  @ApiIgnore @CurrentUser SessionModel sessionModel){
        sceneInfoService.updateSceneInfo(request,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "场景信息删除",notes = "场景信息删除")
    public ResponseEntity<String> deleteSceneInfo(@PathVariable String id,
                                                  @ApiIgnore @CurrentUser SessionModel sessionModel){
        sceneInfoService.deleteSceneInfo(id,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }
}
